#ifndef __TUNER_PROTOCOL_STUFF
#define __TUNER_PROTOCOL_STUFF

/*
 *   This file is part of ed_pvr.
 *
 *   ed_pvr is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   ed_pvr is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with ed_pvr.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef __cplusplus
    extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "timers.h"

#define PROTOCOL_RELOAD_CURRENT_STR		"RELOADONLY"
#define PROTOCOL_INIT_STR				"eTUNER INIT"

#define PROTOCOL_INIT_BAD				0xD0
#define PROTOCOL_INIT_GOOD				0xD1

#define PROTO_CMD_START					0xEDEDED00
#define PROTO_CMD_FILTER				0x000000FF
#define PROTO_CMD_MASK					0xFFFFFF00

#define PROTO_INIT_CONNECTION			1
#define PROTO_TUNE_AND_STREAM			2
#define PROTO_SET_STREAM_POS			3
#define PROTO_GET_STREAM_END_POS		4
#define PROTO_GET_STREAM_POS			5
#define PROTO_GET_STREAM_ID				6

#define PROTO_QUERY_CHANNEL_COUNT		7
#define PROTO_QUERY_CHANNEL_LIST		8
#define PROTO_QUERY_TUNER_COUNT			9

#define PROTO_TIMER_ADD					10
#define PROTO_TIMER_DEL					11
#define PROTO_QUERY_TIMER_LIST			12

#define PROTO_QUERY_REC_LIST			13
#define PROTO_QUERY_REC_COUNT			14
#define PROTO_REC_PLAY					15
#define PROTO_REC_DEL					16

//#define PROTO_GET_STREAM_START_POS		17

#define PROTO_KEEP_ALIVE				18

#define PROTO_GET_CHAN_EPG				19
#define PROTO_QUERY_STREAM_INFO			20

#define PROTO_SET_STREAM_SZ_POS			21
#define PROTO_GET_STREAM_SZ_START_POS	22
#define PROTO_GET_STREAM_SZ_END_POS		23
#define PROTO_GET_STREAM_SZ_POS			24
#define PROTO_GET_STREAM_START_POS2		25

#define PROTO_QUERY_TIMER_COUNT			26
#define PROTO_GET_TIMER_SEQNUM			27
#define PROTO_GET_REC_SEQNUM			28
#define PROTO_RELOAD_EPG_FILE			29


struct protocol_tune_struct
{
	uint32_t 	channel_num;
	uint64_t 	starting_bandwidth;
	uint64_t 	min_bandwidth;
	uint64_t 	max_bandwidth;
	uint8_t 	adaptive;
	uint64_t	game_datetime;
	uint64_t	game_starttime;
	char		aproxy[4096];
	char		fproxy[4096];
	uint8_t		cdn;
};
typedef struct protocol_tune_struct PROTOCOL_TUNE_STRUCT;

struct protocol_channel_struct
{
	char 		name[255];
	int32_t		id;
	int32_t	 	num;
	char 		xmltv_id[8096];
	char 		icon_path[8096];
	uint8_t		is_last;
};
typedef struct protocol_channel_struct PROTOCOL_CHANNEL_STRUCT;


struct protocol_connection_struct
{
	char 		ip[2048];
	uint16_t	port;
	int			connect_timeout;
	int			rw_timeout;
	int			main_socket;
	int			data_socket;
};
typedef struct protocol_connection_struct PROTOCOL_CONNECTION_STRUCT;

struct protocol_cmd_struct
{
	uint8_t cmd;
	uint8_t *dataptr;
	uint32_t dataptr_size;
	int rc;
};
typedef struct protocol_cmd_struct PROTOCOL_CMD_STRUCT;
#ifdef USE_GLIB
// Defines
PROTOCOL_CMD_STRUCT *protocol_get_cmd(int);

int protocol_alive(char *, uint16_t, int);

//size_t protocol_set_tuner_channel(int, uint32_t);
size_t protocol_set_tuner_channel(int, PROTOCOL_TUNE_STRUCT*);
size_t protocol_set_tuner_time_pos(int, uint64_t);

uint64_t protocol_get_tuner_time_pos(int);
uint64_t protocol_get_tuner_time_endpos(int);
uint64_t protocol_get_tuner_time_startpos(int);
uint64_t protocol_get_tuner_time_startpos2(int);
size_t protocol_get_tuner_id(int);
size_t protocol_get_tuner_count(char *, uint16_t, int*);

size_t protocol_send_tuner_init_status(int, uint8_t);
size_t protocol_send_tuner_pos(int, uint64_t);
size_t protocol_send_tuner_id(int, uint8_t);
void protocol_free_cmd_struct(PROTOCOL_CMD_STRUCT *);

size_t protocol_get_channel_count(char *, uint16_t, int *);
size_t protocol_get_channel_list(char *, uint16_t, int*);

size_t protocol_get_rec_count(char *, uint16_t, int *);
size_t protocol_get_rec_list(char *, uint16_t, int*);
//size_t protocol_del_rec_id(char *, uint16_t,  uint32_t, int *);
size_t protocol_del_rec_id(int , uint32_t);
size_t protocol_del_rec_id2(char *, uint16_t, uint32_t , int *);
size_t protocol_play_rec_id(int, uint32_t);

//size_t protocol_stop_rec_id(int, uint32_t);


size_t protocol_get_timer_count(char *, uint16_t, int *);
size_t protocol_get_timer_list(char *, uint16_t, int*);
size_t protocol_add_timer(char *, uint16_t, uint8_t *, uint32_t, int *);
size_t protocol_del_timer(int, uint32_t);
size_t protocol_del_timer2(char *, uint16_t, uint32_t, int *);
size_t protocol_stop_timer(int, uint32_t);

size_t protocol_send_keepalive(int);

//size_t protocol_get_channel_epg(char *, uint16_t, int *, char *);
size_t protocol_get_channel_epg(char *, uint16_t, int *,  TIMER_STRUCT_SEND *);

size_t protocol_get_stream_info(char *, uint16_t, int *);
size_t protocol_get_stream_info2(int);

uint64_t protocol_get_tuner_size_startpos(int);
uint64_t protocol_get_tuner_size_endpos(int);
size_t protocol_get_tuner_size_pos(int);
size_t protocol_set_tuner_size_pos(int, uint64_t);


size_t protocol_get_req_seqnum(char *, uint16_t, int *);
size_t protocol_get_timer_seqnum(char *, uint16_t, int *);

size_t protocol_epg_reload(char *, uint16_t, int *, char *);

// End of Function Declarations
#endif

#ifdef __cplusplus
    }
#endif


#endif

